package chapter1.fundamentals.exercise;

import common.util.ArrayUtil;
import edu.princeton.cs.algs4.StdRandom;

import java.util.Arrays;

/**
 * @author quanlinlin on 2018/11/3 16:58.
 * @version 1.0
 */
public class E_35 {

    public static void main(String[] args) {
        imitate();

        experiment(1000000);
    }

    private static final int SIDES = 6;

    private static void imitate() {

        Double[] dist = new Double[2 * SIDES + 1];
        Arrays.setAll(dist, i -> 0.0);
        for (int i = 1; i <= SIDES; i++) {
            for (int j = 1; j <= SIDES; j++) {
                dist[i + j] += 1.0;
            }
        }

        for (int k = 2; k <= 2 * SIDES; k++) {
            dist[k] /= 36.0;
        }

        System.out.println(ArrayUtil.arrayToString(dist));
    }

    public static void experiment(int N) {
        Double[] arr = new Double[2 * SIDES + 1];
        Arrays.fill(arr, .0);
        for (int i = 0; i < N; i++) {
            int sum = StdRandom.uniform(1, 7) + StdRandom.uniform(1, 7);
            arr[sum] += 1;
        }
        System.out.println(ArrayUtil.arrayToString(arr));
        for (int i = 0; i < arr.length; i++) {
            arr[i] /= N;
        }
        System.out.println(ArrayUtil.arrayToString(arr));

    }
}
